class GunSound {

	private _sound: egret.Sound;
	private _channel: egret.SoundChannel;
	private volume = 0;
	private text;
	constructor(text:any,volume:any) {
		this.text = text;
		this.volume = volume;
		this.loadSound();
	}

	/*** 本示例关键代码段开始 ***/
	//加载
	private loadSound(): void {
		var sound: egret.Sound = this._sound = RES.getRes(this.text);
		this.play();
	}
	//播放
	public play(): void {
		//sound 播放会返回一个 SoundChannel 对象，暂停、音量等操作请控制此对象
		this._channel = this._sound.play(0, -1);
		this._channel.volume = this.volume; //控制音量
		this._channel.addEventListener(egret.Event.SOUND_COMPLETE, this.onComplete, this);

		//  this.addEventListener(egret.Event.ENTER_FRAME, this.onTimeUpdate, this);
	}
	//停止
	public stop(): void {
		if (this._channel) {
			this._channel.removeEventListener(egret.Event.SOUND_COMPLETE, this.onComplete, this);
			// this.removeEventListener(egret.Event.ENTER_FRAME, this.onTimeUpdate, this);

			this._channel.stop();
			this._channel = null;
		}
	}
	//播放完成
	private onComplete(e: egret.Event): void {
//		console.log("播放完成");
		this.stop();
	}
	public volumeCtr(num:any):void{
        	this._channel.volume = num;
	}
}